home *** CD-ROM | disk | FTP | other *** search
/ Tricks of the Mac Game Programming Gurus / TricksOfTheMacGameProgrammingGurus.iso / More Source / C⁄C++ / AIFF DSP v22 / plugin_src / ringmod.c < prev    next >
Text File  |  1995-01-30  |  2KB  |  77 lines

  1. /* ringmod.c: implements fixed-frequency sinusoidal-carrier ring modulation.*/
  2.  
  3. #include "plugin_specific.h"
  4. #include "aiff.h"
  5. #include "sintab.h"
  6. #include <stdlib.h>
  7. #include <limits.h>
  8.  
  9. static short *sintab4, harm;
  10.  
  11. void init_process_ringmod( void )
  12. {
  13.    if ( nh.wdsi != 16 )
  14.       err( "Cannot process files with word size not equal to 16 bits" );
  15.    if ( USHRT_MAX != 65535 )
  16.       err( "this plugin is based on the assumption of 2 byte shorts" );
  17.  
  18.    get_sintab();                 /* get a 1st-quadrant sine wave table */
  19.    sintab4 = gen_sintab4();      /* generate a 4-quadrant sine wave table */
  20.    harm = getusrharm( nh.rate ); /* get harmonic desired from user */
  21. }
  22.  
  23. void term_process_ringmod( void )
  24. {
  25.    free ( sintab4 );
  26. }
  27.  
  28. void process_samdat_ringmod( long buflen )
  29. {
  30.    register long  t;
  31.    register short *td, *tsintab4, tharm, tphase, ttabmask;
  32.    static short phase = 0;
  33.    int chan, fram;
  34.  
  35.    td       = d;
  36.    tsintab4 = sintab4;
  37.    tharm    = harm;
  38.    tphase   = phase;
  39.    ttabmask = TABMASK;
  40.  
  41.    for ( fram=0; fram < buflen; fram++ ) {
  42.       for ( chan=0; chan < nh.chan; chan++ ) {
  43.          t = (long) *td * tsintab4[ tphase &= ttabmask ];
  44. #ifdef THINK_C
  45.          asm { swap t }; /* 1 */
  46. #else
  47.          t >>= 16;
  48. #endif
  49.          *td++ = t;
  50.       }
  51.       tphase += tharm; /* 2 */
  52.    }
  53.    
  54.    phase = tphase;
  55. }
  56. /*
  57. 1. To profile, use t >>= 16 instead.  (Can't profile a function w/ asm.)
  58.  
  59. loop:
  60. 00000026        AND.W     ttabmask,tphase
  61. 00000028        MOVE.W    $00(tsintab4,tphase.W*2),D7
  62. 0000002C        MULS.W    *td,D7
  63. 0000002E        SWAP      D7
  64. 00000030        MOVE.W    D7,*td++
  65. 00000032        ADD.W     harm,tphase
  66. 00000034        CMPA.L    td,end
  67. 00000036        BHI.S     loop
  68. */
  69.  
  70. plugin_info plugin_ringmod = {
  71.    init_process_ringmod,
  72.    term_process_ringmod,
  73.    process_samdat_ringmod,
  74.    1, /* take_input */
  75.    1  /* make_output */
  76. };
  77.